package com.cd.javacxy.common.converter;

import cn.hutool.core.util.StrUtil;
import com.cd.javacxy.common.model.enums.TopicType;
import org.springframework.core.convert.converter.Converter;

/**
 * @author cookie
 */
public class StringToTopicTypeConverter implements Converter<String, TopicType> {

    @Override
    public TopicType convert(String source) {
        String value = source.trim();
        if (StrUtil.isEmpty(value)) {
            return null;
        }
        return TopicType.getTopicTypeByValue(Integer.parseInt(value));
    }

}
